package com.example.compose.timer

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Surface
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.example.compose.ui.theme.ComposeTheme


const val CIRCULAR_TIME_RADIUS = 360f
const val TOTAL_TIME = TimerViewModel.totalTime

@Composable
fun TimerScreen(viewModel: TimerViewModel) {
    val remainingTime = viewModel.remainingTime.collectAsState().value
    val isRunning = viewModel.isRunning.collectAsState().value

    Scaffold(
        topBar = {
            MyTopAppBar(
                isRunning = isRunning,
                onStartClicked = { viewModel.startTimer() },
                onResetClicked = { viewModel.onResetTimer() }
            )
        }
    ) {
        Timer(remainingTime = remainingTime, modifier = Modifier.padding(it))
    }
}

@Composable
fun Timer(remainingTime: Long, modifier: Modifier = Modifier) {
    val transitionData =
        updateCircularTransitionData(remainingTime = remainingTime, totalTime = TOTAL_TIME)
    Box(modifier = modifier.fillMaxSize()) {
        Column(
            modifier = Modifier.fillMaxSize().padding(18.dp)
        ) {

        }
    }

}

@Preview
@Composable
private fun TimerScreenPreview() {
    ComposeTheme {
        Surface(
            modifier = Modifier.fillMaxSize(),
            color = MaterialTheme.colorScheme.background
        ) {
            TimerScreen(viewModel = TimerViewModel())
        }
    }
}